<?php session_start(); 
session_register("gioHang");
?>
<?php
 $sanPham=$this->sanPham; 
 $count=count($sanPham);
?>

<script type="text/javascript">

window.addEvent('domready', function(){
//	$$('.btAddGioHang').addEvent('click', function(e){
//		var log=$('log');
//		var id=this.get('alt');
//		var data={idSanPham: id};
//		var url=rootURL+'/cart/addgiohang';
//		var successFun= function(){ 
//			alert('add san pham co id: '+id);
//		};
//		requestAdv(url,log,data,successFun);
//		});

	$$('.btAddGioHang').each(function(dom){
		var arrayDom=dom.getElements('input');
		var soLuongDom=arrayDom[0];
		var buttonDom=arrayDom[1];
		buttonDom.addEvent('click', function(){
			var id=this.get('alt');
			var sl=soLuongDom.get('value');
			var log=$('log');
			var data={idSanPham: id,soLuong: sl};
			var url=rootURL+'/cart/addgiohang';
			var successFun= function(){ 
				alert('Thêm sản phẩm có id '+id+' với số lượng là '+sl);
			};
			requestAdv(url,log,data,successFun);
			});
		});	
	
});
   </script>
   
   <div id="log"></div>
   <div>
   <div class="center_title_bar">Add giỏ hàng</div>
      <div class="prod_box_big">
        <div class="top_prod_box_big"></div>
        <div class="center_prod_box_big">
<?php 
if($count>0){?>
<table border="1">
<tr>
<td>Mã Sản Phẩm</td>
<td>Tên Sản Phẩm</td>
<td>Giá Bán</td>
<td>Thêm giỏ hàng</td>
</tr>
<?php
for($i=0;$i<count($sanPham);$i++) {
	$maSanPham=$sanPham[$i]['maSanPham'];
	$tenSanPham=$sanPham[$i]['tenSanPham'];
	$giaBan=$sanPham[$i]['giaBan'];
?>
<tr>
<td><?php echo $maSanPham;?></td>
<td><?php echo $tenSanPham;?></td>
<td><?php echo $giaBan;?></td>

<td><div class="btAddGioHang">
<input type="text" name="soLuong" value="" size="2"></input>
<input type="button" value="AddGioHang" alt="<?php echo $maSanPham; ?>">
</div></td>

<?php }?>
</table>
<?php }?>
<form action="<?php echo $this->url(array('action'=>'xemgiohang')); ?>" method="post">
<input type="submit" value="Xem Giỏ Hàng" ></input>
</form>
 </div>
        <div class="bottom_prod_box_big"></div>
      </div>
</div>

